package com.sugar.follow.up.module.business.controller.admin.patient.sqpg.vo;

import cn.hutool.core.collection.CollUtil;
import cn.idev.excel.annotation.ExcelIgnore;
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
import cn.idev.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.sugar.follow.up.module.business.framework.web.convert.ListToStringConverter;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static com.sugar.follow.up.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;

@Schema(description = "管理后台 - 术前评估 Response VO")
@Data
@ExcelIgnoreUnannotated
public class PatientSqpgRespVO {

    @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "5605")
    @ExcelProperty("ID")
    private Long id;

    @Schema(description = "就诊人ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "25218")
    @ExcelProperty("就诊人ID")
    private Long patientId;

    @Schema(description = "就诊人姓名（冗余）", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
    @ExcelProperty("就诊人姓名")
    private String patientName;

    @Schema(description = "录入医生ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1328")
    @ExcelProperty("录入医生ID")
    private Long doctorId;

    @Schema(description = "录入医生姓名（冗余）", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
    @ExcelProperty("录入医生姓名")
    private String doctorName;

    @Schema(description = "检查日期")
    @ExcelProperty("检查日期")
    @JsonSerialize(using = LocalDateSerializer.class) // 序列化（响应）
    @JsonDeserialize(using = LocalDateDeserializer.class) // 反序列化（请求）
    @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY)
    private LocalDate examinationDate;

    @Schema(description = "检查项目")
    @ExcelProperty("检查项目")
    private String examinationProject;

    @Schema(description = "症状（多选：尿频；尿急；尿痛；排尿困难）")
    @ExcelProperty(value = "症状", converter = ListToStringConverter.class)
    private List<String> symptom;

    @Schema(description = "ALT")
    @ExcelProperty("ALT")
    private String alt;

    @Schema(description = "AST")
    @ExcelProperty("AST")
    private String ast;

    @Schema(description = "Cr")
    @ExcelProperty("Cr")
    private String cr;

    @Schema(description = "BUN")
    @ExcelProperty("BUN")
    private String bun;

    @Schema(description = "PSA")
    @ExcelProperty("PSA")
    private String psa;

    @Schema(description = "睾酮")
    @ExcelProperty("睾酮")
    private String testosterone;

    @Schema(description = "WBC")
    @ExcelProperty("WBC")
    private String wbc;

    @Schema(description = "Hb")
    @ExcelProperty("Hb")
    private String hb;

    @Schema(description = "Plt")
    @ExcelProperty("Plt")
    private String plt;

    @Schema(description = "B超（多选：精囊腺；直肠；膀胱）")
    @ExcelProperty(value = "B超", converter = ListToStringConverter.class)
    private List<String> bbUltrasound;

    @Schema(description = "MRI（多选：包膜；精囊腺；淋巴结）")
    @ExcelProperty(value = "MRI", converter = ListToStringConverter.class)
    private List<String> mri;

    @Schema(description = "PSMA（多选：肝脏；肺；淋巴结；骨）")
    @ExcelProperty(value = "PSMA", converter = ListToStringConverter.class)
    private List<String> psma;

    @Schema(description = "ECOG 体能评分")
    @ExcelIgnore
    private List<String> ecog;

    @Schema(description = "ECOG 体能评分")
    @ExcelProperty(value = "ECOG 体能评分", converter = ListToStringConverter.class)
    private List<String> ecogName;

    public void setEcog(List<String> ecog) {
        if (CollUtil.isEmpty(ecog)){
            this.ecogName = Collections.emptyList();
        }

        List<String> ecogName = new ArrayList<>();
        for (String s : ecog) {
            switch (s){
                case "0":
                    ecogName.add("活动能力完全正常，与起病前活动能力无任何差异。");
                    break;
                case "1":
                    ecogName.add("能自由走动及从事轻体力活动，包括一般家务或办公室工作，但不能从事较重的体力活动。");
                    break;
                case "2":
                    ecogName.add("能自由走动及生活自理，但已丧失工作能力，日间不少于一半时间可以起床活动。");
                    break;
                case "3":
                    ecogName.add("生活仅能部分自理，日间一半以上时间卧床或轮椅。");
                    break;
                case "4":
                    ecogName.add("卧床不起，生活不能自理。");
                    break;
                case "5":
                    ecogName.add("死亡。");
                    break;
            }
        }

        this.ecogName = ecogName;
        this.ecog = ecog;
    }

    @Schema(description = "盆底功能锻炼（有；无）")
    @ExcelProperty("盆底功能锻炼")
    private String pdgndl;

    @Schema(description = "骨转移（有；无）")
    @ExcelProperty("骨转移")
    private String gzy;

    @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
    @ExcelProperty("创建时间")
    private LocalDateTime createTime;

}
